package com.h3c.ptability.mapstruct;

import com.h3c.ptability.cache.DeptCache;
import com.h3c.ptability.cache.PtEnumCache;
import com.h3c.ptability.dto.PtWaitSignInfoDTO;
import com.h3c.ptability.entity.PtWaitSignInfo;
import com.h3c.ptability.support.SignExcelInfo;
import com.h3c.ptability.vo.PtEsignRecordDownloadVO;
import com.h3c.ptability.vo.PtWaitSignInfoDownloadVO;
import com.h3c.ptability.vo.PtWaitSignInfoVO;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * @author chenyifan
 * @date 2022/10/25 10:40
 */
@Mapper(uses = DateMapper.class)
public interface PtWaitSignInfoMapstruct {

    PtWaitSignInfoMapstruct INSTANCE = Mappers.getMapper(PtWaitSignInfoMapstruct.class);

    /**
     * dto中的字段同步到实体类中
     *
     * @param ptWaitSignInfoDTOS
     * @return
     */
    @Mapping(source = ".", target = "signExcelInfo.")
    List<PtWaitSignInfo> dtoListToEntityList(List<PtWaitSignInfoDTO> ptWaitSignInfoDTOS);

    /**
     * dto中的字段同步到实体类中
     *
     * @param ptWaitSignInfoDTO
     * @return
     */
    PtWaitSignInfo dtoToEntity(PtWaitSignInfoDTO ptWaitSignInfoDTO);

    /**
     * dto中的字段同步到实体类中
     *
     * @param ptWaitSignInfoDTO
     * @return
     */
    SignExcelInfo dtoToSignExcelInfo(PtWaitSignInfoDTO ptWaitSignInfoDTO);

    /**
     * 实体类中的字段同步到VO中
     *
     * @param ptWaitSignInfoList
     * @return
     */
    List<PtWaitSignInfoVO> entityListToVOList(List<PtWaitSignInfo> ptWaitSignInfoList);

    /**
     * 实体类中的字段同步到VO中
     *
     * @param ptWaitSignInfoList
     * @return
     */
    List<PtWaitSignInfoDownloadVO> entityListToDownloadVOList(List<PtWaitSignInfo> ptWaitSignInfoList);

    /**
     * 填充属性
     *
     * @param voList
     */
    @AfterMapping
    default void afterEntityList2DownloadVoList(@MappingTarget List<PtWaitSignInfoDownloadVO> voList) {
        voList.forEach(s -> {
            if (Objects.isNull(s.getSignRecordStatus())) {
                s.setSignStatus("待发起");
            } else {
                s.setSignStatus(s.getSignRecordStatus().getStatusName());
            }
            s.setSceneType(PtEnumCache.getEnumDataInRedis("ptability-manage", "ES_SCENE_TYPE", s.getSceneType()));
        });
    }
}
